package com.example.fw;

import org.openqa.selenium.By;

public class NavigationHelper extends HelperBase {
	private String baseUrl = manager.getProperty("baseUrl", "http://localhost/addressbookv4.1.4/");
	private String groupList =  manager.getProperty("groupListPage", "group.php");
	private String contactList =  manager.getProperty("contactList", "index.php");
	private String printPhonesTable =  manager.getProperty("printPhonesTable", "view.php?all&print&phones");		
	
	public void openAddressBook(){
		openUrl(baseUrl);
	}
	
	public NavigationHelper(ApplicationManager manager) {
		super(manager);
	}

	public void openGroupListPage() {
		if (!isElementPresent(By.id(manager.getProperty("navigation", "nav")))){ openAddressBook(); }
		if (!(getDriver().getCurrentUrl().equals(baseUrl + groupList)))
			click(By.linkText(manager.getProperty("navGroupsList", "groups")));
		else if (!isElementPresent(By.name(manager.getProperty("groupsAddNewButton", "new"))))
			click(By.linkText(manager.getProperty("navGroupsList", "groups")));		
	}

	public void openContactListPage() {
		if (!isElementPresent(By.id(manager.getProperty("navigation", "nav")))){ openAddressBook(); }
		if (!(getDriver().getCurrentUrl().equals(baseUrl)))
			if (!(getDriver().getCurrentUrl().equals(baseUrl + contactList)))
				click(By.linkText(manager.getProperty("navContactsList", "home")));	
	}
	
	public void openPrintPhonesPage() {
		if (!isElementPresent(By.id(manager.getProperty("navigation", "nav")))){ openAddressBook(); }
		if (!(getDriver().getCurrentUrl().equals(baseUrl + printPhonesTable)))
				click(By.linkText(manager.getProperty("navPhones", "print phones")));	
	}
}
